home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Programming / Wipeout / source / taskinfo.c < prev    next >
C/C++ Source or Header  |  1998-04-12  |  3KB  |  135 lines

  1. /*
  2.  * $Id: taskinfo.c 1.4 1998/04/12 18:03:10 olsen Exp olsen $
  3.  *
  4.  * :ts=4
  5.  *
  6.  * Wipeout -- Traces and munges memory and detects memory trashing
  7.  *
  8.  * Written by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
  9.  * Public Domain
  10.  */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "global.h"
  14. #endif    /* _GLOBAL_H */
  15.  
  16. /******************************************************************************/
  17.  
  18. STRPTR
  19. GetTaskTypeName(LONG type)
  20. {
  21.     STRPTR table[TASKTYPE_CLI_Program-TASKTYPE_Task+1] =
  22.     {
  23.         "task",
  24.         "process",
  25.         "CLI program"
  26.     };
  27.  
  28.     ASSERT(TASKTYPE_Task <= type && type <= TASKTYPE_CLI_Program);
  29.  
  30.     /* map a name to a task type */
  31.     return(table[type]);
  32. }
  33.  
  34. /******************************************************************************/
  35.  
  36. LONG
  37. GetTaskType(struct Task * whichTask)
  38. {
  39.     struct Process * pr;
  40.     LONG result;
  41.  
  42.     /* this routine determines whether the current task
  43.      * is only a plain Task, a plain Process or a CLI
  44.      * which executes a command
  45.      */
  46.  
  47.     if(whichTask != NULL)
  48.         pr = (struct Process *)whichTask;
  49.     else
  50.         pr = (struct Process *)FindTask(NULL);
  51.  
  52.     if(pr->pr_Task.tc_Node.ln_Type == NT_PROCESS)
  53.     {
  54.         result = TASKTYPE_Process;
  55.  
  56.         if(pr->pr_CLI != NULL)
  57.         {
  58.             struct CommandLineInterface * cli = BADDR(pr->pr_CLI);
  59.  
  60.             if(IsValidAddress((ULONG)cli))
  61.             {
  62.                 STRPTR commandName = BADDR(cli->cli_CommandName);
  63.     
  64.                 if(IsValidAddress((ULONG)commandName))
  65.                 {
  66.                     if(commandName[0] != 0)
  67.                     {
  68.                         result = TASKTYPE_CLI_Program;
  69.                     }
  70.                 }
  71.             }
  72.         }
  73.     }
  74.     else
  75.     {
  76.         result = TASKTYPE_Task;
  77.     }
  78.  
  79.     return(result);
  80. }
  81.  
  82. BOOL
  83. GetTaskName(struct Task * whichTask,STRPTR name,LONG nameLen)
  84. {
  85.     struct Process * pr;
  86.     BOOL gotName = FALSE;
  87.  
  88.     /* determine the name of the given task; if it is in fact
  89.      * a process, check whether it is really a CLI with a program
  90.      * running in it and get its name
  91.      */
  92.  
  93.     if(whichTask != NULL)
  94.         pr = (struct Process *)whichTask;
  95.     else
  96.         pr = (struct Process *)FindTask(NULL);
  97.  
  98.     if(pr->pr_Task.tc_Node.ln_Type == NT_PROCESS && pr->pr_CLI != NULL)
  99.     {
  100.         struct CommandLineInterface * cli = BADDR(pr->pr_CLI);
  101.  
  102.         if(IsValidAddress((ULONG)cli))
  103.         {
  104.             STRPTR commandName = BADDR(cli->cli_CommandName);
  105.  
  106.             if(IsValidAddress((ULONG)commandName))
  107.             {
  108.                 if(commandName[0] != 0)
  109.                 {
  110.                     int len = commandName[0];
  111.     
  112.                     if(len >= nameLen)
  113.                         len = nameLen-1;
  114.     
  115.                     strncpy(name,&commandName[1],len);
  116.                     name[len] = '\0';
  117.     
  118.                     gotName = TRUE;
  119.                 }
  120.             }
  121.         }
  122.     }
  123.  
  124.     if(NOT gotName)
  125.     {
  126.         if(IsValidAddress((ULONG)pr->pr_Task.tc_Node.ln_Name))
  127.         {
  128.             StrcpyN(nameLen,name,pr->pr_Task.tc_Node.ln_Name);
  129.             gotName = TRUE;
  130.         }
  131.     }
  132.  
  133.     return(gotName);
  134. }
  135.